<script>
/*
 * Franchise exports its state into an HTML file which, when loaded in a web browser,
 * transfers that data to the Franchise app (without ever uploading anything to a server).
 * This file makes that possible. It's loaded within an iframe, and recieves the data by
 * postMessage, stores it in sessionStorage, and then redirects to the final URL. 
 */

window.addEventListener("message", function(e){
    if(typeof e.data === 'string'){
        sessionStorage.importData = e.data;
        try {
            window.top.location.replace(location.href.replace('reciever.html', ''))
        } catch (err) {
            window.top.location = location.href.replace('reciever.html', '')
        }
    }else if(e.data.action === 'franchise-transfer-data'){
        sessionStorage.importData = e.data.importData;
        event.source.postMessage({
            action: 'franchise-redirect',
            url: location.href.replace('reciever.html', '')
        }, '*'); // this can't be event.origin because that is null for file://
    }

}, false);
</script>